package org.example.hansp.sort;

import java.util.Arrays;
import java.util.Comparator;

public class BubbleSortPro {
    public static void main(String[] args) {
        int[] arr={2,-1,8,6,9,99};
        bubbleSort(arr, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                int o11 = (int) o1;
                int o21 = (int) o2;
                return o11 - o21;
            }
        });
        System.out.println(Arrays.toString(arr));

    }
    public static void bubbleSort(int[] arr, Comparator<Integer> comp) {
        for (int i = 0; i < arr.length - 1; i++) {
            boolean flag = false;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (comp.compare(arr[j], arr[j + 1]) > 0) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    flag = true;
                }
            }
            if (!flag) {
                break;
            }

        }
    }
}
